import { ResPage, User } from "@/api/interface/index";
// import { PORT1 } from "@/api/config/servicePort";
// import qs from "qs";

import http from "@/api";

/**
 * @name 用户模块
 */
// * 获取用户列表
export const getUserList = (pageNum: number = 1, pageSize: number = 10, wrapper?: Partial<User.UserInfo>) => {
	return http.post<ResPage<User.UserInfo>>(`/users/getUserList/${pageNum}/${pageSize}`, { wrapper });
};

export const registerUserApi = (register: User.Register) => {
	return http.post<User.UserInfo>("/users/register", register);
};

// 获取用户信息
export const getUserInfo = () => {
	return http.get<User.UserInfo>("/users/getUserInfo");
};

// 修改用户信息
export const updateUserInfo = (userInfo: Partial<User.UserInfo>) => {
	return http.post<string>("/users/updateUserInfo", userInfo);
};

// 删除用户
export const deleteUser = (id: number | string) => {
	return http.delete("/users/delete/" + id);
};

export const getUserDetailApi = (id: number) => {
	return http.post<User.UserInfo>("/users/getUserDetail", {
		id
	});
};

export const getRoleListApi = (pageNum: number, pageSize: number, wrapper?: Partial<User.Role>) => {
	return http.post<ResPage<User.Role>>(`/role/getList/${pageNum}/${pageSize}`, { wrapper });
};

export const addRoleApi = (role: User.Role) => {
	return http.post<string>("/role/create", role);
};

export const updateRoleApi = (role: Partial<User.Role>) => {
	return http.post<string>("/role/update", role);
};

export const deleteRoleApi = (id: number) => {
	return http.delete<string>(`/role/delete/${id}`);
};

export const getRoleDetailApi = (id: number) => {
	return http.get<User.Role>(`/role/getdetail/${id}`);
};

export const getPermissionListApi = (pageNum: number, pageSize: number, wrapper?: Partial<User.Permission>) => {
	return http.post<ResPage<User.Permission>>(`/permission/getList/${pageNum}/${pageSize}`, { wrapper });
};

export const addPermissionApi = (permission: User.Permission) => {
	return http.post<string>("/permission/create", permission);
};

export const updatePermissionApi = (permission: User.Permission) => {
	return http.post<string>("/permission/update", permission);
};

export const deletePermissionApi = (id: number) => {
	return http.delete<string>(`/permission/delete/${id}`);
};

export const getPermissionDetailApi = (id: number) => {
	return http.get<User.Permission>(`/permission/getdetail/${id}`);
};

export const updatePassword = (userId: number, user_name: string, password: string) => {
	return http.post<string>(`/users/updatepwd`, { userId, user_name, password });
};
